/**
 * @author linyip
 */
var VappList = new Pearlsen.BaseEdit({
	gridId:'vappGrid',
	formId:'vappGrid',
	advSearchId:'advSearchWin',
	module:'vapp',
	modulePath:'/pages/rms/vappmgr/',
	moduleName:'vapp',
	idProperty:'VAPP_NAME',
	nameProperty:'VAPP_DESCRIBE',
	dataSetHandler:'VAPPMgrDataSetHandler',
	queryHandler:'VAPPMgrQueryHandler',
	
	statusRender:function(value){
    var val = "";
    switch (value) {
        case "POWERED_ON":
            val = "<span style='color:green;'>正在运行</span>";
            break;
        case "POWERED_OFF":
            val = "<span style='color:red;'>已停止</span>";
            break;
        case "SUSPENDED":
        	val = "<span style='color:red;'>已停止</span>";
        	break;
    }
    return val;
},
	
initFun:function(){
	
	var VDC_Name = this.getQueryString("VDC_Name");
	var query=new Query('VappMgrQueryHandler','VappMgrQueryHandler');
	query.setHandlerMethod("handler");

	query.addCondition("VDC_Name",VDC_Name);
 	query.setCompletedFun(this.afterloadForm);
 	query.setCompletedFunScope(this);
 	query.load();		
},


afterloadForm:function(success,dataset,response, opts){
	if(success){
		if( dataset && !Ext.isEmpty(dataset.record)){
			this.dataset=dataset;			
		}
	}else{
		
	}
},

goToVM:function(){		
	var me = VappList;
	var record= Ext.getCmp("vappGrid").getSelectionModel().getLastSelected();
	if(!record){
		Pearlsen.Utils.showInfoMsg("请选择一条记录");	
		return;
	}
	parent.MainTab.addTab(record.get('VAPP_NAME'),"主机维护","/pages/rms/vmmgr/VMMgr.jsp?VDC_Name="+record.get('VAPP_VDC')+"&VApp_Name="+record.get('VAPP_NAME'));
},

powerOnVapp:function()
{
	var me = VappList;
	var record= Ext.getCmp("vappGrid").getSelectionModel().getLastSelected();
	if(!record){
		Pearlsen.Utils.showInfoMsg("请选择一条记录");	
		return;
	}
	var ds=new DataSet('VappMgrDatasetHandler','VappMgrDatasetHandler');
  	ds.setHandlerMethod("powerOnVapp");
  	ds.addCondition("VAPP_VDC", record.get('VAPP_VDC'));
  	ds.addCondition("VAPP_NAME",record.get('VAPP_NAME'));
  	ds.execute(me.powerOnVappCallBack);
},

powerOnVappCallBack:function(result)
{
	if( result.success ){
		Pearlsen.Utils.showInfoMsg("正在开机!");	
		
		
	}else{
		Pearlsen.Utils.showErrorMsg("出错了,原因:"+result.message);
	}
},

shutdownVapp:function()
{
	var me = VappList;
	var record= Ext.getCmp("vappGrid").getSelectionModel().getLastSelected();
	if(!record){
		Pearlsen.Utils.showInfoMsg("请选择一条记录");	
		return;
	}
	var ds=new DataSet('VappMgrDatasetHandler','VappMgrDatasetHandler');
  	ds.setHandlerMethod("shutdownVapp");
  	ds.addCondition("VAPP_VDC", record.get('VAPP_VDC'));
  	ds.addCondition("VAPP_NAME",record.get('VAPP_NAME'));
	ds.execute(me.shutdownVappCallBack);
},

shutdownVappCallBack:function(result)
{
	if( result.success ){
		Pearlsen.Utils.showInfoMsg("正在关机!");		
	}else{
		Pearlsen.Utils.showErrorMsg("出错了,原因:"+result.message);
	}
},

suspendVapp:function(){
	var me = VappList;
	var record= Ext.getCmp("vappGrid").getSelectionModel().getLastSelected();
	if(!record){
		Pearlsen.Utils.showInfoMsg("请选择一条记录");	
		return;
	}
	var ds=new DataSet('VappMgrDatasetHandler','VappMgrDatasetHandler');
  	ds.setHandlerMethod("suspendVapp");
  	ds.addCondition("VAPP_VDC", record.get('VAPP_VDC'));
  	ds.addCondition("VAPP_NAME",record.get('VAPP_NAME'));
	ds.execute(me.suspendVappCallBack);
},

suspendVappCallBack:function(result)
{
	if( result.success ){
		Pearlsen.Utils.showInfoMsg("正在挂起!");		
	}else{
		Pearlsen.Utils.showErrorMsg("出错了,原因:"+result.message);
	}
},

refreshVapp:function(){

	window.location.reload(); 
}



	
});